package thread.unLock;

public class Solution {
    public static void main(String[] args) {
        Object lock1 = new Object();
        Object lock2 = new Object();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized(lock1) {
                    System.out.println("t1获取到lock1");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("t1在拿到lock1的情况下，尝试获取lock2");
                    synchronized(lock2) {
                        System.out.println("t1获取到lock2");
                    }
                }
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized(lock1) {
                    System.out.println("t2获取到lock1");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("t2在拿到lock1的情况下，尝试获取lock2");
                    synchronized(lock2) {
                        System.out.println("t2获取到lock2");
                    }
                }
            }
        });

        t1.start();
        t2.start();
    }
}
